module game {
    export class Processor_HLSZ extends puremvc.SimpleCommand implements puremvc.ICommand {
        public constructor() {
            super();
        }
        public static NAME: string = "Processor_HLSZ";
        private hlszProxy: HlszProxy = null;
        /**
         * 注册消息
         */
        public register(): void {
            this.facade.registerCommand("Processor_HLSZ", Processor_HLSZ);
        }
        public execute(notification: puremvc.INotification): void {
            this.hlszProxy = HlszProxy.getProxy();
            var body: any = notification.getBody();//携带数据
            let msgdata = DataParser.WSReceiveMsg(RegDataHlsz, body);
            if (Global.isEmpty(msgdata)) {
                return;
            }
            let mainCmd = msgdata["mainCmd"];
            let subCmd = msgdata["subCmd"];
            let data = msgdata["msgData"];
            if (InstructionsEnum.IS_TEST) {
                console.log("炸金花接收：", mainCmd, subCmd, msgdata)
            }
            if (Global.isEmpty(data)) {
                return;
            }
            switch (mainCmd) {
                case 1: {
                    if (subCmd == 100) {//登陆成功
                        this.hlszProxy.login(data);
                    }
                    if (subCmd == 101) {//登陆异常
                        Global.tipShow(data["szDescribeString"]);
                        SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HLSZ);
                        InstructionsEnum.ID_GAME = "";
                    }
                    if (subCmd == 102) { //登陆完成
                        let obj = {
                            wVisit: 0,
                            wVersion: 101122049,
                            wGameVersion: 101122049
                        }
                        SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.HLSZ, RegDataHlsz.CMD_GF_GameOption, obj, true);
                    }
                    if (subCmd == 103) { //回到其他房间
                        SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HLSZ);
                        game.AppFacade.instance.sendNotification(PanelNotify.HALL.HALL_RECONNECTGAME, data["wServerID"]);
                    }
                    if (subCmd == 104) {//中途断线重连
                        this.hlszProxy.login(data);
                    }
                    break;
                }
                case 2: {
                    if (subCmd == 101) {//房间配置
                        this.hlszProxy.getRoomInfo(data);
                    };
                    break;
                }
                case 3: {
                    if (subCmd == 100) {//刷新广场人员信息
                        this.hlszProxy.userJoinSquare(data)
                    };
                    if (subCmd == 101) {//
                        this.hlszProxy.getUserInfo(data);
                    }
                    if (subCmd == 102) {//我分配到的座位
                        this.hlszProxy.userStateModify(data);
                    }
                    if (subCmd == 103) {//钱不够入座
                        SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HLSZ)
                        Global.tipShow(data["szDescribeString"])
                    }
                    break;
                }
                case 4: {
                    if (subCmd == 100) {//请求坐下
                        let obj = {
                            wTableID: 65535,
                            wChairID: 65535,
                            szInsurePass: ""
                        }
                        SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.HLSZ, RegDataHlsz.CMD_GR_UserSitDown, obj, true);
                    }
                }
                case 8: {
                    if (subCmd == 100) {//游戏状态
                        this.hlszProxy.getGameStatus(data);
                    };
                    if (subCmd == 103) {//

                    };
                    if (subCmd == 104) {//

                    };
                    if (subCmd == 200) {//
                        switch (data["wType"]) {
                            case 256:
                                let obj = {
                                    CODE: PanelNotify.HLSZ.CLOSE_PLAY_GAME,
                                    TEXT: "抱歉！您的金币不足，请前往充值！",
                                    NEXT: true,
                                }
                                game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_TIP, obj);
                                break;
                            case 512:
                                SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HLSZ);
                                Global.tipShow("房间已关闭")
                                break;
                            case 515:
                                SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HLSZ);
                                Global.tipShow("房间已关闭")
                                break;
                        }
                    };
                    break;
                }
                case 100: {
                    if (subCmd == 100) {
                        //空闲
                        if (data["cbGameStatus"] == 0) {
                            RegDataHlsz.MainCMD_MsgId[100][101] = RegDataHlsz.free
                        }
                        // 游戏中
                        if (data["cbGameStatus"] == 100) {
                            RegDataHlsz.MainCMD_MsgId[100][101] = RegDataHlsz.gameStart
                        }
                    }
                    if (subCmd == 101) {//中途加入
                        this.hlszProxy.dataRecovery(data);
                    }
                    if (subCmd == 200) {//后端推送消息
                        if (data["wType"] == 515) {
                            Global.tipShow(data["szString"]);
                        } else {
                            EffectUtils.textFadeAway(data["szString"]);
                        }
                    }
                    if (subCmd == 300) {//牌局编号
                        this.hlszProxy.getSerialNumber(data);
                    }
                    break;
                }
                case 200: {
                    if (subCmd == 100) {//游戏开始
                        this.hlszProxy.StartGame(data);
                    };
                    if (subCmd == 101) {//下注
                        this.hlszProxy.XiaZhu(data);
                    };
                    if (subCmd == 102) {//弃牌
                        this.hlszProxy.QiPai(data);
                    };
                    if (subCmd == 106) {//看牌
                        this.hlszProxy.KanPai(data);
                    };
                    if (subCmd == 105) {//比牌
                        this.hlszProxy.BiPai(data);
                    }
                    if (subCmd == 104) {//结算
                        this.hlszProxy.gameOver(data);
                    }
                    break;
                }
                // case 1000: {
                //     if (subCmd == 1) {
                //          EffectUtils.textFadeAway(data["szString"]);
                //     }
                //     break;
                // }
            }
        }
    }
}
